<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>法律列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script type="text/javascript" src="../assets/js/jquery-1.8.3.min.js"></script>
    <script src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <div class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="username"  id="name" placeholder="请输入作者" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn"  lay-submit="" id="butt" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>

                </div>
                <div class="layui-card-body ">
                    <table class="layui-hide" id="test" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script id="barDemo" type="text/html">

    <a title="删除" lay-event="sc">
        <i class="layui-icon">&#xe640;</i>
    </a>
</script>
<script>
    layui.use(['table', 'jquery'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        $.ajax({
            type:"GET",
            url:"http://localhost:8080/api/flxc",
            data:{"title":null},
            headers:{
                token:localStorage.getItem("token")
            },
            datatype: "json",
            success:function (data){
                table.render({
                    elem: '#test'
                    ,data:data.data
                    ,toolbar: '#toolbarDemo'
                    ,title: '社区公告'
                    ,page:{
                        limits:[10,15,20,25],
                        limit:10
                    }
                    ,cols: [[
                        ,{field:'lid', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                        ,{field:'ltitle', width:120, title: '标题'}
                        ,{field:'lauthor', title:'作者', width:170, edit: 'text'}
                        ,{field:'linfo', title:'详情信息', width:60, edit: 'text', sort: true,width:200}
                        ,{field:'lcreateTime', title:'发布时间', width:190, sort: true}
                        ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
                    ]]
                });
            }
        })
        $("#butt").click(function (){
            let name=$("#name").val();
            $.ajax({
                type:"GET",
                url:"http://localhost:8080/api/cxflxc",
                data:{"name":name},
                headers:{
                    token:localStorage.getItem("token")
                },
                datatype: "json",
                success:function (data){
                    table.render({
                        elem: '#test'
                        ,data:data.data
                        ,toolbar: '#toolbarDemo'
                        ,title: '社区公告'
                        ,page:{
                            limits:[10,15,20,25],
                            limit:10
                        }
                        ,cols: [[
                            ,{field:'lid', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                            ,{field:'ltitle', width:120, title: '标题'}
                            ,{field:'lauthor', title:'作者', width:170, edit: 'text'}
                            ,{field:'linfo', title:'详情信息', width:60, edit: 'text', sort: true,width:200}
                            ,{field:'lcreateTime', title:'发布时间', width:190, sort: true}
                            ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
                        ]]
                    });
                }
            })
        })
    })
    layui.use(['table','jquery','layer'], function(){
        var table = layui.table;
        var $obj=layui.jquery;
        var layer=layui.layer;
        //监听工具条
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

            if(layEvent === 'xz'){ //查看
                layer.open({
                    type: 2,
                    title:'新增社区公告',
                    content: ['notice-edit.html','no'],
                    area: ['1300px', '700px'],
                    resize:false,
                    move: false,
                    end:function(){
                        location.reload();//弹出层结束后，刷新主页面
                    }
                });
            }else if(layEvent === 'xg'){
                sessionStorage.setItem("nid",data.nid);
                sessionStorage.setItem("name",data.name);
                sessionStorage.setItem("ntitle",data.ntitle);
                sessionStorage.setItem("ncontent",data.ncontent);
                sessionStorage.setItem("nreleasetime",data.nreleasetime);
                layer.open({
                    type: 2,
                    title:'修改社区公告',
                    content: ['notice-edit.html','no'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    area: ['1000px', '600px'],
                    resize:false,
                    move: false,
                    end:function(){
                        location.reload();//弹出层结束后，刷新主页面
                    }
                });
            }else if(layEvent === 'sc'){
                if (confirm("确定要删除吗?")){
                    $.ajax({
                        type:'POST',
                        url: "http://localhost:8080/api/scflxc",
                        data: {"id": data.lid},
                        headers: {
                            token: localStorage.getItem("token")
                        },
                        datatype: "json",
                        success: function (data) {
                            if(data.data>0){
                                layer.msg('删除成功!',{
                                    icon:1
                                    ,time:1000
                                },function (){
                                    location.reload();
                                });
                            }

                        }
                    })
                }
            }
        });
    });

</script>
